<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>computeUnitOfWork</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="../../libs/babel.min.js"></script>
    <script src="../../libs/react-17.0.2.js"></script>
    <script src="../../libs/react-dom-17.0.2.js"></script>
    <script type="text/babel">
      const App = props => {
        const [color, setColor] = React.useState("red")

        const [num, setNum] = React.useState(1)

        const ref = React.useRef()

        const onUpdate = () => {
          setColor(color === "red" ? "green" : "red")
        }

        React.useEffect(() => {
          console.log("creaete--", color)
          return () => {
            console.log("desc", color)
          }
        }, [color])

        React.useLayoutEffect(() => {
          console.log("useLayoutEffect creaete--", color)
          console.log("useLayoutEffect ref--", ref.current)
          setNum(num => num + 1)
          return () => {
            console.log("useLayoutEffect desc", color)
          }
        }, [color])

        return (
          <div>
            <div className="is-21">
              <div className="is-211">211{color}</div>
              <div className="is-212">212</div>
            </div>
            z爱傻傻的
            <button onClick={onUpdate}>切换颜色</button>
            <div className="is-23" ref={ref} style={{ color: color }}>
              <div className="is-231">231</div>
              <div className="is-232">232</div>
            </div>
          </div>
        )
      }
      const root = document.getElementById("root")

      ReactDOM.render(<App app={1} />, root)
      console.dir(root)
    </script>
  </body>
</html>
